import 'package:elmer_tools/common/GlobalState.dart';
import 'package:elmer_tools/model/ConfigModel.dart';
import 'package:elmer_tools/model/ResponseBody.dart';
import 'package:elmer_tools/pages/welcome/ServiceBottomSheet.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:getwidget/components/bottom_sheet/gf_bottom_sheet.dart';

class Configuration extends StatefulWidget {
    
    const Configuration({super.key});


    @override
    State<StatefulWidget> createState() => ConfigurationState();
}

class ConfigurationState extends State<Configuration> {
    
    bool isLoading = true;
    final GFBottomSheetController _controller = GFBottomSheetController();

    @override
    Widget build(BuildContext context) {
        
        return Center(
            child: isLoading ? SpinKitWave(
                color: Colors.blue,
                size: 30.0,
            ) : Servicebottomsheet(),
        );
    }
    
    @override
    void initState() {
        super.initState();

        loadConfig();
        print("----InitState---");
        // Initialization logic here
    }
    void showLoading() {
        setState(() {
            isLoading = true;
        });
    }
    void hideLoading() {
        setState(() {
            isLoading = false;
        });
    }
    void loadConfig() {
        final api = GlobalState.apiService;
        api?.send<ConfigModel>(
            "config.getConfig",
            null,
            (json) => ConfigModel.fromJson(json as Map<String, dynamic>)
        ).then((data) => print(data.data?.theme))
        .catchError((error) {
            print(error);
            hideLoading();
        });
    }
}